 /* 
 * File:   cCamera.cpp
 * Author: josep
 * 
 * Created on 12 / desembre / 2010, 01:06
 */

#include "cCamera.h"

cCamera::cCamera() {
    DirectionX=0;
    DirectionY=0;
    WorldOrigin[X]=0;
    WorldOrigin[Y]=0;
    WorldDimension[X]=INFINITY;
    WorldDimension[Y]=INFINITY;
}

cCamera::cCamera(const cCamera& orig):cPositionedObject(orig) {
    DirectionX=orig.DirectionX;
    DirectionY=orig.DirectionY;
}

cCamera::~cCamera() {
}

void cCamera::Show(){
    PosX+=GetDirectionX()*GetSpeedX();
    PosY+=GetDirectionY()*GetSpeedY();
    if(PosX<WorldOrigin[X]){
        PosX=WorldOrigin[X];
        DirectionX=0;
    }
    if(PosY<WorldOrigin[Y]){
        PosY=WorldOrigin[Y];
        DirectionY=0;
    }
    if(WorldDimension[X]!=INFINITY && PosX>WorldOrigin[X]+WorldDimension[X]-GetWidth()){
        PosX=WorldOrigin[X]+WorldDimension[X]-GetWidth();
        DirectionX=0;
    }
    if(WorldDimension[Y]!=INFINITY && PosY>WorldOrigin[Y]+WorldDimension[Y]-GetHeight()){
        PosX=WorldOrigin[Y]+WorldDimension[Y]-GetHeight();
        DirectionY=0;
    }

    glTranslatef(-GetPosX(),-GetPosY(), 0);
}

void cCamera::Init(int Width, int Height, float SpeedX, float SpeedY, int PosX, int PosY){
    cPositionedObject::Init(PosX, PosY, Width, Height);
    SetSpeedX(SpeedX);
    SetSpeedY(SpeedY);
}

void cCamera::SetDirectionY(int DirectionY) {
    this->DirectionY = DirectionY;
}
int cCamera::GetDirectionY() const {
    return DirectionY;
}
void cCamera::SetDirectionX(int DirectionX) {
    this->DirectionX = DirectionX;
}
int cCamera::GetDirectionX() const {
    return DirectionX;
}
void cCamera::SetWorldOrigin(int dir, int Origin) {
    this->WorldOrigin[dir] = Origin;
}
int cCamera::GetWorldOrigin(int dir) const {
    return WorldOrigin[dir];
}

void cCamera::SetWorldDimension(int dir, int dim) {
    this->WorldDimension[dir] = dim;
}
int cCamera::GetWorldDimension(int dir) const {
    return WorldDimension[dir];
}
